package com.lagou.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lagou.entity.UserCourseOrder;
import com.lagou.service.OrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("order")
public class OrderController {
    @Reference
    private OrderService orderService;

    @GetMapping("saveOrder/{userId}/{courseId}/{activityCourseId}/{sourceType}")
    public String saveOrder(@PathVariable String userId, @PathVariable String courseId,
                            @PathVariable String activityCourseId, @PathVariable String sourceType) {
        String orderNo = UUID.randomUUID().toString();
        orderService.saveOrder(orderNo, userId, courseId, activityCourseId, sourceType);

        return orderNo;
    }

    @GetMapping("updateOrder/{orderNo}/{status}")
    public Integer updateOrder(@PathVariable String orderNo, @PathVariable Integer status) {
        return orderService.updateOrder(orderNo, status);
    }

    @GetMapping("deleteOrder/{orderNo}")
    public Integer deleteOrder(@PathVariable String orderNo) {
        return orderService.deleteOrder(orderNo);
    }

    @GetMapping("getOrdersByUserId/{userId}")
    public List<UserCourseOrder> getOrdersByUserId(@PathVariable String userId) {
        return orderService.getOrdersByUserId(userId);
    }
}
